package com.mo.common.domain;

import javax.xml.crypto.Data;
import java.io.Serializable;
import java.util.HashMap;

/**
 * @author msy
 * @date 2022/3/22
 */
public class AjaxResult extends HashMap<String,Object> implements Serializable {
    private final String CODE = "code";
    private final String MSG = "msg";
    private final String DATA = "data";

    public AjaxResult(){
    }
    public AjaxResult(Integer code,String msg,Object data){
        super.put(CODE,code);
        super.put(MSG,msg);
        super.put(DATA,data);
    }
    public AjaxResult(Integer code,String msg){
        super.put(CODE,code);
        super.put(MSG,msg);
    }

    public static AjaxResult success(){
        return new AjaxResult(0,"操作成功");
    }
    public static AjaxResult error(){
        return new AjaxResult(500,"操作失败");
    }

    public static AjaxResult successObj(Object data){
        if (data == null) {
            error();
        }
        return new AjaxResult(0,"操作成功",data);
    }
    public AjaxResult errorObj(Object data){
        return new AjaxResult(500,"操作失败",data);
    }
}
